import 'package:flutter/material.dart';
import 'package:net/model/notice_mo.dart';
import 'package:net/model/video_model.dart';
import 'package:net/navigator/hi_navigator.dart';
import 'package:hi_base/format_util.dart';
import 'package:hi_base/view_util.dart';

class NoticeCard extends StatelessWidget {
  NoticeItemMo noticeItemMo;
  NoticeCard({Key key, @required this.noticeItemMo}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => handleBannerClick(noticeItemMo),
      child: Container(
        decoration: BoxDecoration(border: borderLine(context)),
        padding: EdgeInsets.only(left: 15, right: 15, bottom: 10, top: 5),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [_buildIcon(), hiSpace(width: 10), _buildContents()],
        ),
      ),
    );
  }

  _buildIcon() {
    var iconData = noticeItemMo.type == 'video'
        ? Icons.ondemand_video_outlined
        : Icons.card_giftcard;
    return Icon(
      iconData,
      size: 30,
    );
  }

  _buildContents() {
    return Flexible(
        child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              noticeItemMo.title,
              style: TextStyle(fontSize: 16),
            ),
            Text(dateMonthAndDay(noticeItemMo.createTime)),
          ],
        ),
        hiSpace(height: 5),
        Text(
          noticeItemMo.subtitle,
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        )
      ],
    ));
  }

  void handleBannerClick(NoticeItemMo noticeItemMo) {
    if (noticeItemMo.type == 'video') {
      HiNavigator.geInstance().onJumpTo(RouteStatus.detail, args: {
        "videoMo": VideoModel(vid: noticeItemMo.url, cover: noticeItemMo.cover),
      });
    } else {
      HiNavigator.geInstance().openH5(noticeItemMo.url);
    }
  }
}
